package com.gyz.taxiplus;

import java.util.List;

import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class WelcomeActivity extends Activity {

	private Button search;
	private Button fee;
	private boolean providergps = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		search = (Button) findViewById(R.id.search);
		search.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(WelcomeActivity.this, SearchActivity.class);
				startActivity(intent);
			}

		});
		fee = (Button) findViewById(R.id.fee);
		fee.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(WelcomeActivity.this, FeeActivity.class);
				startActivity(intent);
				finish();
			}

		});
		ConnectivityManager connectivitymanager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		LocationManager locationmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		List<String> providers = locationmanager.getProviders(true);
		for (String s : providers) {
			if (s.equals("gps")) {
				providergps = true;
			}
		}
		boolean showsettings = false;
		if (!connectivitymanager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
				.isConnected()
				&& !connectivitymanager.getNetworkInfo(
						ConnectivityManager.TYPE_MOBILE).isConnected()) {
			Toast.makeText(getApplicationContext(), R.string.errornonetwork,
					Toast.LENGTH_SHORT).show();
			showsettings = true;
		}
		if (!providergps) {
			Toast.makeText(getApplicationContext(), R.string.errornoprovider,
					Toast.LENGTH_SHORT).show();
			showsettings = true;
		}
		if (showsettings) {
			startActivity(new Intent(Settings.ACTION_SETTINGS));
			finish();
		}
	}

	public static final int geoTransfer(double source) {
		return (int) (source * 1E6);
	}

}